﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gma.QrCodeNet.Encoding;

namespace QrcodeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;//将背景色调为白色
            Console.ForegroundColor = ConsoleColor.Black;//将字体色调为黑色
            Console.Write(@"Type some text to QR code:");//提示用户输入字符串

            string sampleText = Console.ReadLine();//输入的字符串存入变量sampleText 中

            while (sampleText.Length > 10)//如果字符串的长度大于10，提示用户重新输入
            {
                Console.WriteLine("Please enter a string with a length less than 10");
                sampleText = Console.ReadLine();
            }
            
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);//QrEncoder类实例化，qrEncoder
            QrCode qrCode = qrEncoder.Encode(sampleText);//QrCode类实例化，并将sampleText作为参数
            for (int j = 0; j < qrCode.Matrix.Width; j++)//输出qrCode每个位置的字符
            {
                for (int i = 0; i < qrCode.Matrix.Width; i++)
                {
                    char charToPrint = qrCode.Matrix[i, j] ? '█' : '　';
                    Console.Write(charToPrint);
                }
                Console.WriteLine();
            }
            Console.WriteLine(@"Press any key to quit.");//提示用户输入结束
           
            FormQrcode frqrcode = new FormQrcode();
            frqrcode.ShowDialog();
            Console.ReadKey();
        }
    }
}
